package com.woniu.controller;

import com.woniu.utils.MinioUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Classname UploadController
 * @Description TODO
 * @Date 2025/8/20 9:38
 * @Created by pc
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Resource
    private MinioUtil minioUtil;

    @PostMapping
    public Map<String,Object> upload(MultipartFile file) throws Exception {
        Map<String, Object> map = minioUtil.uploadFile(file, "data35");
        // 存地址
        // http://localhost:9000/data35/data35_1755654531403.png
        String url = (String)map.get("url");
        // url.substring()
        return map;
    }

    public static void main(String[] args) {
        String url = "http://localhost:9000/data35/data35_1755654531403.png";
        int i = url.indexOf("data35");
        // System.out.println();
        String suffix = url.substring(i);
        System.out.println(suffix);
    }
}
